<?php

namespace App\Models\user;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\user\MoneyDetail
 *
 * @property int $id
 * @property int $user_id 关联用户ID
 * @property int $amount 流转金额
 * @property string $title 标题
 * @property int $pm 0 = 支出 1 = 获得
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail whereAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail wherePm($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\user\MoneyDetail whereUserId($value)
 * @mixin \Eloquent
 */
class MoneyDetail extends Model
{

    protected $fillable = [
        'user_id',
        'title',
        'amount',
        'pm',
        'resource_id'

    ];

    public function getAmountAttribute($value)
    {

        if ($value > 0 && $this->pm == 1){
            return '+'.$value;
        }
        if ($value < 0){
            return (string) $value;
        }

        if ($value > 0 && $this->pm == 0){
            return "-".$value;
        }
        return (string) $value;

    }
}
